{include file="common/head"/}
<div class="admin-main layui-anim layui-anim-upbit">
    <fieldset class="layui-elem-field layui-field-title">
        <legend>{:lang('奖品')}{:lang('list')}</legend>
    </fieldset>
    <div class="demoTable">
        <div class="layui-inline">
            <button type="button" class="layui-btn " id="delAll">批量删除</button>
        </div>
        <div class="layui-inline">
            <button type="button" class="layui-btn " id="showAll">批量显示</button>
        </div>
        <div class="layui-inline">
            <button type="button" class="layui-btn " id="hiddenAll">批量隐藏</button>
        </div>
        <a href="{:url('edit')}" class="layui-btn layui-btn-danger">添加奖品</a>
        <div class="layui-inline">
            <select lay-verify="required" style="width: 150px" class="layui-input layui-unselect" id="type_id" >
                <option value=>请选择奖品归属</option>
                <option value='1'>竞彩问答</option>
                <option value='2'>推演</option>
            </select>
        </div>
    </div>
    <table class="layui-table" id="list" lay-filter="list"></table>
</div>
{include file="common/foot"/}
<script type="text/html" id="action">

    <a href="{:url('edit')}?prize_id={{d.prize_id}}" class="layui-btn layui-btn-xs">{:lang('edit')}</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<script>
    layui.use('table', function() {
        var table = layui.table, $ = layui.jquery;
        var tableIn = table.render({
            id: 'content',
            elem: '#list',
            url: '{:url("prize")}',
            method: 'post',
            page: true,
            cols: [[
                {checkbox: true, fixed: true},
                {field: 'prize_id', title: '{:lang("id")}', width: 80,fixed: true},
                {field: 'prize', title: '奖品名称', width: 120},
                {field: 'limitnum', title: '限量', width: 80},
                {field: 'parent_id', title: '礼品类型', width: 120},
                {field: 'is_delete', title: '状态', width: 180},
                {width: 200, align: 'center', toolbar: '#action'}
            ]],
            limit: 10 //每页默认显示的数量
        });
        //站点筛选
        $('#type_id').on('change', function () {
            var type_id = $(this).val();

            tableIn.reload({
                where: {type_id: type_id}
            });
            var loading = layer.load(1, {shade: [0.1, '#fff']});
            $.post("{:url('prize')}", {type_id:type_id}, function (res) {
                layer.close(loading);

            });
        });
        table.on('tool(list)', function(obj) {
            var data = obj.data;
            if (obj.event === 'del') {
                layer.confirm('您确定要删除该留言吗？', function(index){
                    var loading = layer.load(1, {shade: [0.1, '#fff']});
                    $.post("{:url('prizedel')}",{prize_id:data.prize_id},function(res){
                        layer.close(loading);
                        if(res.code===1){
                            layer.msg(res.msg,{time:1000,icon:1});
                            tableIn.reload();
                        }else{
                            layer.msg('操作失败！',{time:1000,icon:2});
                        }
                    });
                    layer.close(index);
                });
            }
        });
        $('#delAll').click(function(){
            layer.confirm('确认要删除选中的内容吗？', {icon: 3}, function(index) {
                layer.close(index);
                var checkStatus = table.checkStatus('content'); //content即为参数id设定的值
                var ids = [];
                $(checkStatus.data).each(function (i, o) {
                    ids.push(o.prize_id);
                });
                var loading = layer.load(1, {shade: [0.1, '#fff']});
                $.post("{:url('delAll')}", {ids: ids}, function (data) {
                    layer.close(loading);
                    if (data.code === 1) {
                        layer.msg(data.msg, {time: 1000, icon: 1});
                        tableIn.reload();
                    } else {
                        layer.msg(data.msg, {time: 1000, icon: 2});
                    }
                });
            });
        })
        $('#showAll').click(function(){
            layer.confirm('确认要显示选中的内容吗？', {icon: 3}, function(index) {
                layer.close(index);
                var checkStatus = table.checkStatus('content'); //content即为参数id设定的值
                console.log(checkStatus)
                var ids = [];
                $(checkStatus.data).each(function (i, o) {
                    console.log(o)
                    ids.push(o.prize_id);
                });

                var loading = layer.load(1, {shade: [0.1, '#fff']});
                $.post("{:url('showAll')}", {ids: ids}, function (data) {
                    layer.close(loading);
                    if (data.code === 1) {
                        layer.msg(data.msg, {time: 1000, icon: 1});
                        tableIn.reload();
                    } else {
                        layer.msg(data.msg, {time: 1000, icon: 2});
                    }
                });
            });
        })
        $('#hiddenAll').click(function(){
            layer.confirm('确认要显示选中的内容吗？', {icon: 3}, function(index) {
                layer.close(index);
                var checkStatus = table.checkStatus('content'); //content即为参数id设定的值
                var ids = [];
                $(checkStatus.data).each(function (i, o) {
                    ids.push(o.prize_id);
                });
                var loading = layer.load(1, {shade: [0.1, '#fff']});
                $.post("{:url('hiddenAll')}", {ids: ids}, function (data) {
                    layer.close(loading);
                    if (data.code === 1) {
                        layer.msg(data.msg, {time: 1000, icon: 1});
                        tableIn.reload();
                    } else {
                        layer.msg(data.msg, {time: 1000, icon: 2});
                    }
                });
            });
        })
    });
</script>